package secretaryGUI;

import java.sql.SQLException;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableCellRenderer;

import secretary.getClasses;
import guiCode.secretaryScreenCode;

public class viewExistingClasses {
	secretaryScreenCode ssc;
	secretaryAlerts sa = new secretaryAlerts();
	getClasses gc = new getClasses();
	
	public void buttonClick(secretaryScreenCode code, createSecretaryWindow csw){
		ssc = code;
		if(ssc.getEditMode()==6){
			try {
				// if(ssc.getSemesterForEdit()==1){
				
				csw.table_1.setModel(ssc.getClasses(ssc.getSemesterForEdit()));
				DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
				centerRenderer.setHorizontalAlignment(JLabel.CENTER);
				for (int i = 0; i < csw.table_1.getColumnCount(); i++)
					csw.table_1.getColumnModel().getColumn(i)
							.setCellRenderer(centerRenderer);
				csw.table.setEnabled(true);
				// }
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			csw.alertsLbl.setText("Click on 'Create new class' to open the create new class wizard. Click on 'Edit exisiting class to open the edit exisiting class wizard.");
		}
		else{
			try {
				// if(ssc.getSemesterForEdit()==1){
				
				csw.table.setModel(ssc.getClasses(ssc.getSemesterForEdit()));
				DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
				centerRenderer.setHorizontalAlignment(JLabel.CENTER);
				for (int i = 0; i < csw.table.getColumnCount(); i++)
					csw.table.getColumnModel().getColumn(i)
							.setCellRenderer(centerRenderer);

				csw.btnEditExistingClass.setEnabled(true);
				csw.btnCreateNewClass.setEnabled(true);
				csw.table.setEnabled(false);
				// }
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			csw.alertsLbl.setText("Click on 'Create new class' to open the create new class wizard. Click on 'Edit exisiting class to open the edit exisiting class wizard.");
		}
		
	}
}
